package com.codelife.one.Clone;

/**
 * @ClassName Demo1
 * @Description TODO
 * @Date 2019/10/22 15:41
 * @Version 1.0
 *
 * Cloneable 实现深克隆 引用类型参数 也要实现clone方法 同时需要在当前对象中配置 这个对象的转换
 **/
public class Demo1 implements Cloneable{

    private String name;

    private Stuend stuend;

    public Stuend getStuend() {
        return stuend;
    }

    public void setStuend(Stuend stuend) {
        this.stuend = stuend;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    @Override
    protected Object clone() throws CloneNotSupportedException {
        Demo1 demo1=null;
        try{
             demo1= (Demo1)super.clone();
        }catch (Exception e){
            System.out.println(e);
        }
        demo1.stuend=(Stuend) stuend.clone();
       return demo1;
    }

    /*@Override
    protected Object clone() throws CloneNotSupportedException {
        return super.clone();
    }
*/
    @Override
    public String toString() {
        return "Demo1{" +
                "name='" + name + '\'' +
                ", stuend=" + stuend +
                '}';
    }
}
